import React, {Fragment, PureComponent} from 'react';
import {connect} from 'dva';
import {
  Badge,
  Button,
  Card,
  Col,
  Divider,
  Dropdown,
  Form,
  Icon,
  Input,
  InputNumber,
  Menu,
  Modal,
  Radio,
  Row,
  Select,
} from 'antd';
import TableList from '@/components/TableList';
import {nameMaxLength, remarkMaxLength, ruleP} from '@/utils/rule'
import styles from '../search.less';
import { encode,decode } from '@/utils/AesUtil';


const FormItem = Form.Item;
const {TextArea} = Input;
const {Option} = Select;
const RadioGroup = Radio.Group;
const ftpTypeMap = [' ', ' '];
const ftpType = ['FTP', 'SFTP'];
const statusMap = ['success', 'error'];
const status = ['启用', '禁用'];
const formLayout = {
  labelCol: {span: 6},
  wrapperCol: {span: 18},
};

const CreateForm = Form.create()(props => {
  const {
    modalVisible,
    form,
    handleAdd,
    handleModalVisible,
    form: {getFieldValue},
    linkInfo,
    handleTest,
    unicodeList,
    setUploading,
    uploading,
  } = props;
  const okHandle = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      form.resetFields();
      handleAdd(fieldsValue);
    });
  };
  const handleLink = () => {
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      setUploading();
      handleTest(fieldsValue);
    });
  }
  return (
    <Modal
      destroyOnClose
      width={800}
      title="新增配置"
      visible={modalVisible}
      onOk={okHandle}
      onCancel={() => handleModalVisible()}
      maskClosable={false}
    >
      <Row gutter={16}>
        <Col md={12}>
          <FormItem {...formLayout} label="系统名称">
            {form.getFieldDecorator('name', {
              rules: [{required: true, message: '系统名称不能为空'}, {max: nameMaxLength()[0], message: nameMaxLength()[1]}],
            })(<Input placeholder="请输入"/>)}
          </FormItem>
        </Col>
        <Col md={12}>
          <FormItem {...formLayout} label="IP地址">
            {form.getFieldDecorator('ipAddr', {
              rules: [{required: true, message: 'IP地址不能为空'},
                {pattern: new RegExp(ruleP(3)[0], 'g'), message: ruleP(3)[1]}],
            })(<Input placeholder="请输入"/>)}
          </FormItem>
        </Col>

        <Col md={12}>
          <FormItem {...formLayout} label="端口号">
            {form.getFieldDecorator('port', {
              rules: [{required: true, message: '端口号不能为空'},
                {pattern: new RegExp(ruleP(2)[0], 'g'), message: ruleP(2)[1]}],
            })(<InputNumber placeholder="请输入" min={0} max={65535} style={{width: '100%'}}/>)}
          </FormItem>
        </Col>

        <Col md={12}>
          <FormItem {...formLayout} label="用户名">
            {form.getFieldDecorator('userCode', {
              rules: [{required: true, message: '用户名不能为空'}, {max: nameMaxLength()[0], message: nameMaxLength()[1]}],
            })(<Input placeholder="请输入"/>)}
          </FormItem>
        </Col>
        <Col md={12}>
          <FormItem {...formLayout} label="密码">
            {form.getFieldDecorator('password', {
              rules: [{required: true, message: '密码不能为空'}]
            })(<Input placeholder="请输入" type="password"/>)}
          </FormItem>
        </Col>

        <Col md={12}>
          <FormItem {...formLayout} label="FTP类型">
            {form.getFieldDecorator('ftpType', {
              initialValue: "0"
            })(
              <Radio.Group>
                <Radio value="0">
                  FTP
                </Radio>
                <Radio value="1">
                  SFTP
                </Radio>
              </Radio.Group>
            )}
          </FormItem>
        </Col>

        <Col md={12} style={{display: getFieldValue('ftpType') === '1' ? 'none' : 'block',}}>
          <FormItem {...formLayout} label="模式">
            {form.getFieldDecorator('ftpMode', {
              initialValue: "0"
            })(
              <Radio.Group>
                <Radio value="0">
                  主动模式
                </Radio>
                <Radio value="1">
                  被动模式
                </Radio>
              </Radio.Group>
            )}
          </FormItem>
        </Col>

        <Col md={12}>
          <FormItem {...formLayout} label="语言编码">
            {form.getFieldDecorator('unicode', {initialValue: "UTF-8"})(
              <Select placeholder="请选择" style={{width: '100%'}}>
                {
                  unicodeList && unicodeList.map((item, index) => {
                    return (<Option key={index} value={item.value}>{item.name}</Option>)
                  })
                }
              </Select>
            )}
          </FormItem>
        </Col>

        <Col md={12}>
          <FormItem {...formLayout} label="是否共享">
            {form.getFieldDecorator('isShare', {
              initialValue: "0"
            })(
              <Radio.Group>
                <Radio value="0">
                  不共享
                </Radio>
                <Radio value="1">
                  共享
                </Radio>
              </Radio.Group>
            )}
          </FormItem>
        </Col>


        <Col md={12} style={{display: getFieldValue('isShare') === '0' ? 'block' : 'none',}}>
          <FormItem {...formLayout} label="自动移动">
            {form.getFieldDecorator('issync', {
              initialValue: "0"
            })(
              <Radio.Group>
                <Radio value="0">
                  否
                </Radio>
                <Radio value="1">
                  是
                </Radio>
              </Radio.Group>
            )}
          </FormItem>
        </Col>


        {getFieldValue('isShare') == '0' ? <Col md={12}>
          <FormItem {...formLayout} label="帐号关系">
            {form.getFieldDecorator('syncType', {
              initialValue: '1'
            })(
              <Radio.Group>
                <Radio value='1'>
                  无
                </Radio>
                <Radio value='2'>
                  主从帐号
                </Radio>
              </Radio.Group>
            )}
          </FormItem>
        </Col> : null}


        <Col md={24}>
          <FormItem labelCol={{span: 3}} wrapperCol={{span: 21}} label="备注">
            {form.getFieldDecorator('remark', {rules: [{max: remarkMaxLength()[0], message: remarkMaxLength()[1]}]})(
              <TextArea
                style={{minHeight: 32}}
                rows={2}
              />)}
          </FormItem>
        </Col>

        <Col md={4}><Button type="primary" onClick={handleLink}
                            loading={uploading}>{uploading ? '连接中' : '测试连接'}</Button></Col>
        {linkInfo && linkInfo.msg ? (
          <Col md={20} style={{paddingTop: '5px'}}><Icon style={{color: linkInfo.result == 'ok' ? 'green' : '#f5222d'}}
                                                         type={linkInfo.result == 'ok' ? 'check-circle' : 'close-circle-o'}/> {linkInfo.msg}
          </Col>
        ) : null}
      </Row>
    </Modal>
  );
});

@Form.create()
class UpdateForm extends PureComponent {
  static defaultProps = {
    handleUpdate: () => {
    },
    handleUpdateModalVisible: () => {
    },
    values: {},
  };

  constructor(props) {
    super(props);
    this.state = {
      formVals: {
        name: props.values.name,
        ftpType: props.values.ftpType,
        ftpMode: props.values.ftpMode,
        ipAddr: props.values.ipAddr,
        port: props.values.port,
        userCode: props.values.userCode,
        password: props.values.password,
        passwordCheck: props.values.password,
        unicode: props.values.unicode,
        isShare: props.values.isShare,
        issync: props.values.issync,
        syncType: props.values.syncType || '1',
        remark: props.values.remark,
        id: props.values.id,
        status: props.values.status,
        unicodeList: [],
      },
    };
  }

  //编辑，确定提交
  handleCheck = checkBtn => {
    const {form, handleUpdate} = this.props;
    const {formVals: oldValue} = this.state;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const formVals = {...oldValue, ...fieldsValue};
      this.setState(
        {
          formVals,
        },
        () => {
          handleUpdate(formVals);
        }
      );
    });
  };
  renderFooter = checkBtn => {
    const {handleUpdateModalVisible, values} = this.props;
    return [
      <Button key="cancel" onClick={() => handleUpdateModalVisible(false, values)}>
        取消
      </Button>,
      <Button key="forward" type="primary" onClick={() => this.handleCheck(checkBtn)}>
        确定
      </Button>,
    ];
  };

  handleLink = () => {
    const {handleTest, form, setUploading, values} = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      setUploading();
      handleTest(fieldsValue, values);
    });
  }
  onShareRadioChange = e => {
    console.log('radio checked', e.target.value);

    let tempValues = this.state.formVals;
    tempValues.isShare = e.target.value;
    this.setState({
      formVals: tempValues,
    });
  };


  render() {
    const {
      updateModalVisible, handleUpdateModalVisible, values, form,
      form: {getFieldValue}, linkInfo, unicodeList, uploading, 
    } = this.props;
    const {checkBtn, formVals} = this.state;
    return (
      <Modal
        width={800}
        bodyStyle={{padding: '32px 40px 48px'}}
        destroyOnClose
        title="编辑配置"
        visible={updateModalVisible}
        footer={this.renderFooter(checkBtn)}
        onCancel={() => handleUpdateModalVisible(false, values)}
        afterClose={() => handleUpdateModalVisible()}
        maskClosable={false}
      >

        <Row gutter={16}>
          <Col md={12}>
            <FormItem id="name" {...formLayout} label="系统名称">
              {form.getFieldDecorator('name', {
                rules: [{required: true, message: '系统名称不能为空'}, {max: nameMaxLength()[0], message: nameMaxLength()[1]}],
                initialValue: formVals.name
              })(<Input placeholder="请输入"/>)}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem id="ipAddr" {...formLayout} label="IP地址">
              {form.getFieldDecorator('ipAddr', {
                rules: [{required: true, message: 'IP地址不能为空'},
                  {pattern: new RegExp(ruleP(3)[0], 'g'), message: ruleP(3)[1]}
                ], initialValue: formVals.ipAddr
              })(<Input placeholder="请输入"/>)}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem id="port" {...formLayout} label="端口号">
              {form.getFieldDecorator('port', {
                rules: [{required: true, message: '端口号不能为空'}, {
                  pattern: new RegExp(ruleP(2)[0], 'g'),
                  message: ruleP(2)[1]
                }], initialValue: formVals.port
              })(<InputNumber placeholder="请输入" min={0} max={65535} style={{width: '100%'}}/>)}
            </FormItem>
          </Col>
          <Col md={12}>
            <FormItem id="userCode" {...formLayout} label="用户名">
              {form.getFieldDecorator('userCode', {
                rules: [{required: true, message: '用户名不能为空'}, {max: nameMaxLength()[0], message: nameMaxLength()[1]}],
                initialValue: formVals.userCode
              })(<Input placeholder="请输入"/>)}
            </FormItem>
          </Col>
          <Col md={12}>
            <FormItem id="password" {...formLayout} label="密码">
              {form.getFieldDecorator('password', {
                rules: [{required: true, message: '密码不能为空'}], initialValue: formVals.password
              })(<Input placeholder="请输入" type="password"/>)}
            </FormItem>
            <FormItem id="passwordCheck" style={{display: 'none'}} {...formLayout} label="密码">
              {form.getFieldDecorator('passwordCheck', {
                rules: [{required: true, message: '密码不能为空'}], initialValue: formVals.passwordCheck
              })(<Input placeholder="请输入" type="passwordCheck"/>)}

            </FormItem>

          </Col>

          <Col md={12}>
            <FormItem id="ftpType" {...formLayout} label="FTP类型">
              {form.getFieldDecorator('ftpType', {
                initialValue: formVals.ftpType
              })(
                <Radio.Group>
                  <Radio value={0}>
                    FTP
                  </Radio>
                  <Radio value={1}>
                    SFTP
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>


          <Col md={12} style={{display: getFieldValue('ftpType') == '1' ? 'none' : 'block',}}>
            <FormItem id="ftpMode" {...formLayout} label="模式">
              {form.getFieldDecorator('ftpMode', {initialValue: formVals.ftpMode.toString()})(
                <Radio.Group>
                  <Radio value="0">
                    主动模式
                  </Radio>
                  <Radio value="1">
                    被动模式
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem id="unicode" {...formLayout} label="语言编码">
              {form.getFieldDecorator('unicode', {initialValue: formVals.unicode})(
                <Select placeholder="请选择" style={{width: '100%'}}>
                  {
                    unicodeList && unicodeList.map((item, index) => {
                      return (<Option key={index} value={item.value}>{item.name}</Option>)
                    })
                  }
                </Select>
              )}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem id="isShare" {...formLayout} label="是否共享">
              {form.getFieldDecorator('isShare', {initialValue: formVals.isShare.toString()})(
                <Radio.Group onChange={this.onShareRadioChange}>
                  <Radio value="0">
                    不共享
                  </Radio>
                  <Radio value="1">
                    共享
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>
          <Col md={12} style={{display: getFieldValue('isShare') == '0' ? 'block' : 'none',}}>
            <FormItem id="issync" {...formLayout} label="自动移动">
              {form.getFieldDecorator('issync', {initialValue: formVals.issync + ''})(
                <Radio.Group>
                  <Radio value="0">
                    否
                  </Radio>
                  <Radio value="1">
                    是
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>

          <Col md={12} style={{display: (getFieldValue('isShare') == '0') ? 'block' : 'none',}}>
            <FormItem id="syncType" {...formLayout} label="帐号关系">
              {form.getFieldDecorator('syncType', {initialValue: formVals.syncType + ''})(
                <Radio.Group>
                  <Radio value='1'>
                    无
                  </Radio>
                  <Radio value='2'>
                    主从帐号
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>


          <Col md={12}>
            <FormItem {...formLayout} label="状态">
              {form.getFieldDecorator('status', {
                initialValue: formVals.status
              })(
                <Radio.Group>
                  <Radio value={0}>
                    启用
                  </Radio>
                  <Radio value={1}>
                    禁用
                  </Radio>
                </Radio.Group>
              )}
            </FormItem>
          </Col>


          <Col md={24}>
            <FormItem id="remark" labelCol={{span: 3}} wrapperCol={{span: 21}} label="备注">
              {form.getFieldDecorator('remark', {
                rules: [{max: remarkMaxLength()[0], message: remarkMaxLength()[1]}],
                initialValue: formVals.remark
              })(
                <TextArea
                  style={{minHeight: 32}}
                  rows={2}
                />)}
            </FormItem>
          </Col>
          <Col md={4}><Button type="primary" onClick={this.handleLink}
                              loading={uploading}>{uploading ? '连接中' : '测试连接'}</Button></Col>
          {linkInfo && linkInfo.msg ? (
            <Col md={20} style={{paddingTop: '5px'}}><Icon
              style={{color: linkInfo.result == 'ok' ? 'green' : '#f5222d'}}
              type={linkInfo.result == 'ok' ? 'check-circle' : 'close-circle-o'}/> {linkInfo.msg}</Col>
          ) : null}
        </Row>
      </Modal>
    );
  }
}

/* eslint react/no-multi-comp:0 */
@connect(({outerFiles, loading}) => ({
  outerFiles,
  loading: loading.models.outerFiles,
}))
@Form.create()
class outerFiles extends PureComponent {
  state = {
    modalVisible: false,
    updateModalVisible: false,
    expandForm: false,
    selectedRows: [],
    formValues: {},
    stepFormValues: {},
    linkInfo: {}, //连接成功后者失败提示信息
    //详情
    detailVisible: false,
    detailsData: {},
    uploading: false,
  };


  columns = [
    {
      title: '系统名称',
      dataIndex: 'name',
    },
    {
      title: 'IP地址',
      dataIndex: 'ipAddr',
    },
    {
      title: 'FTP类型',
      dataIndex: 'ftpType',
      render(val) {
        return ftpType[val];
      },
    },
    {
      title: '用户名',
      dataIndex: 'userCode',
    },
    // {
    //   title: '已用空间',
    //   dataIndex: 'useDiskSize',
    // },
    // {
    //   title: '总空间',
    //   dataIndex: 'diskSize',
    // },
    {
      title: '状态',
      dataIndex: 'status',
      render(val) {
        return <Badge status={statusMap[val]} text={status[val]}/>;
      },

    },
    {
      title: '操作',
      render: (text, record) => (
        <Fragment>
          <a onClick={() => this.detailHandelVisible(true, text)}>详情</a>
          <Divider type="vertical"/>
          <Dropdown
            overlay={
              <Menu>
                <Menu.Item onClick={() => this.handleUpdateModalVisible(true, record)}>编辑</Menu.Item>
                <Menu.Item onClick={() => this.deleteData(text.id)}>删除</Menu.Item>
              </Menu>
            }
          >
            <a>更多 <Icon type="down"/></a>
          </Dropdown>

        </Fragment>
      ),
    },
  ];
  deleteData = (id) => {
    Modal.confirm({
      title: '删除',
      content: '您确定要删除以下数据吗？',
      okText: '确认',
      cancelText: '取消',
      onOk: () => this.handleThisRowDelete(id),
    });
  };
  setUploading = () => {
    this.setState({
      uploading: true,
    })
  }

  batchDelete = (rows = []) => {
    const ids = rows.map((item) => {
      return item.id;
    }).join(",");
    this.deleteData(ids); //批量删除
  };
  handleThisRowDelete = (id) => {
    const {dispatch} = this.props;
    dispatch({
      type: 'innerFiles/remove',
      payload: {id},
      callback: (res) => {
        if (res.result == "ok") {
          Modal.success({title: res.msg});
          this.pageList();
          this.setState({selectedRows: []})
        } else {
          Modal.error({title: '操作失败', content: res.msg});
        }
      },//callback
    });
  }

  componentDidMount() {
    const {dispatch} = this.props;
    this.pageList();
    dispatch({
      type: 'outerFiles/unicodeList',
      payload: {
        dataDictTypeCode: 'charset',
      },
      callback: (res) => {
        if (res.result == "ok") {
          this.setState({unicodeList: res.data.dataList,}
          )
        }
      },
    });//语言编码
  }

  // 分页查询列表
  pageList(res, pageSize = 10, pageNum = 0) {
    const {dispatch} = this.props;
    const values = {
      isOutFtp: 1,
      name: res && res.name,
      pageSize: pageSize,
      pageNum: pageNum,
    };
    dispatch({
      type: 'outerFiles/queryList',
      payload: values,
      callback: (obj) => {
        if (obj.result == "ok" && res.userName) {
          this.treeData();// 组织树查询
        }
      },
    });
  }

  handleStandardTableChange(pagination, filters, sorter) {
    const {formValues} = this.state;
    // 分页请求
    this.pageList(formValues, pagination.pageSize, pagination.current - 1);
  }


  handleSelectRows = rows => {
    this.setState({
      selectedRows: rows,
    });
  };

  //查询
  handleSearch = e => {
    e.preventDefault();
    const {dispatch, form} = this.props;
    form.validateFields((err, fieldsValue) => {
      if (err) return;
      const values = {
        ...fieldsValue,
        updatedAt: fieldsValue.updatedAt && fieldsValue.updatedAt.valueOf(),
      };
      this.setState({
        formValues: values,
      });
      this.pageList(values);
    });
  };

  handleModalVisible = flag => {
    this.setState({
      modalVisible: !!flag,
      linkInfo: {}
    });
  };

  detailHandelVisible = (flag, text) => {
    this.setState({
      detailVisible: !!flag,
      detailsData: text,
    });
  };

  handleUpdateModalVisible = (flag, record) => {
    this.setState({
      updateModalVisible: !!flag,
      stepFormValues: record || {},
      linkInfo: {}
    });
  };

  //测试连接
  handleTest =async (fields, text) => {
    const {dispatch} = this.props;
    //密码这儿特殊处理一下
    let passwordCheck = fields.passwordCheck;
    let password = fields.password;

    let lastpassword =await encode(password);
    if (passwordCheck && password) {
      //如果两个相等，表示密码没有修改，并且是加密的
      if (passwordCheck == password) {
        lastpassword = password;
      }
    }


    dispatch({
      type: 'outerFiles/test',
      payload: {
        id: text && text.id || '',
        isOutFtp: 1,
        name: fields.name,
        ftpType: fields.ftpType,
        ftpMode: fields.ftpMode,
        ipAddr: fields.ipAddr,
        port: fields.port,
        userCode: fields.userCode,
        // password: this.encData(fields.password),
        password: lastpassword,
        unicode: fields.unicode,
        isShare: fields.isShare,
        remark: fields.remark,
        status: fields.status
      },
      callback: (res) => {
        this.setState({
          linkInfo: res,
          uploading: false,
        })
      },
    });
  };





  //新增
  handleAdd =async fields => {
    const {dispatch} = this.props;
    if (fields.isShare == 1) {
      //共享的时候是不能同步的
      fields.issync = 0;
    }

    dispatch({
      type: 'outerFiles/add',
      payload: {
        isOutFtp: 1,
        name: fields.name,
        ftpType: fields.ftpType,
        ftpMode: fields.ftpMode,
        ipAddr: fields.ipAddr,
        port: fields.port,
        userCode: fields.userCode,
        // password: this.encData(fields.password),
        password:await encode(fields.password),
        unicode: fields.unicode,
        isShare: fields.isShare,
        remark: fields.remark,
        status: fields.status,
        issync: fields.issync,
        syncType: fields.syncType || '1',
      },
      callback: (res) => {
        if (res.result == "ok") {
          Modal.success({
            title: res.msg,
          });
          dispatch({
            type: 'outerFiles/queryList',
            payload: {isOutFtp: 1,}
          });
        } else {
          Modal.error({
            title: '操作失败',
            content: res.msg,
          });
        }
      },
    });
    this.handleModalVisible();
  };

  //编辑
  handleUpdate =async fields => {
    const {dispatch} = this.props;
    const {formValues} = this.state;

    //密码这儿特殊处理一下
    let passwordCheck = fields.passwordCheck;
    let password = fields.password;

    let lastpassword =await encode(password);
    if (passwordCheck && password) {
      //如果两个相等，表示密码没有修改，并且是加密的
      if (passwordCheck == password) {
        lastpassword = password;
      }
    }

    if (fields.isShare == 1) {
      //共享的时候是不能同步的
      fields.issync = 0;
    }
    dispatch({
      type: 'outerFiles/update',
      payload: {
        isOutFtp: 1,
        name: fields.name,
        ftpType: fields.ftpType,
        ftpMode: fields.ftpMode,
        ipAddr: fields.ipAddr,
        port: fields.port,
        userCode: fields.userCode,
        // password: this.encData(fields.password),
        password: lastpassword,
        unicode: fields.unicode,
        isShare: fields.isShare,
        remark: fields.remark,
        id: fields.id,
        status: fields.status,
        issync: fields.issync,
        syncType: fields.syncType || '1',
      },
      callback: (res) => {
        if (res.result == "ok") {
          Modal.success({
            title: res.msg,
          });
          dispatch({
            type: 'outerFiles/queryList',
            payload: {isOutFtp: 1,}
          });
        } else {
          Modal.error({
            title: '操作失败',
            content: res.msg,
          });
        }
      },//callback
    });

    this.handleUpdateModalVisible();
  };

  renderSimpleForm() {
    const {
      form: {getFieldDecorator},
    } = this.props;
    return (
      <Form onSubmit={this.handleSearch} layout="inline">
        <Row gutter={{md: 8, lg: 24, xl: 48}}>
          <Col md={8} sm={24}>
            <FormItem label="系统名称">
              {getFieldDecorator('name')(<Input placeholder="请输入"/>)}
            </FormItem>
          </Col>

          <Col md={8} sm={24}>
            <span className={styles.submitButtons}>
              <Button type="primary" htmlType="submit">
                查询
              </Button>
            </span>
          </Col>
        </Row>
      </Form>
    );
  }

  renderForm() {
    return this.renderSimpleForm();
  }

  render() {
    const {
      outerFiles: {data},
      loading,
      form,
    } = this.props;
    const {selectedRows, modalVisible, updateModalVisible, stepFormValues, linkInfo, detailVisible, detailsData, unicodeList, uploading} = this.state;

    const parentMethods = {
      handleAdd: this.handleAdd,
      handleModalVisible: this.handleModalVisible,
      handleTest: this.handleTest,
      setUploading: this.setUploading,
    };
    const updateMethods = {
      handleUpdateModalVisible: this.handleUpdateModalVisible,
      handleUpdate: this.handleUpdate,
      handleTest: this.handleTest,
      setUploading: this.setUploading,
    };

    const detailsMethods = {
      detailHandelVisible: this.detailHandelVisible,
    };

    return (
      <Card bordered={false}>
        <CreateForm {...parentMethods} modalVisible={modalVisible} linkInfo={linkInfo} unicodeList={unicodeList}
                    uploading={uploading}/>
        <div className={styles.tableList}>
          <div className={styles.tableListForm}>{this.renderForm()}</div>
          <div className={styles.tableListOperator}>
            <Button icon="plus" type="primary" onClick={() => this.handleModalVisible(true)}>
              新增
            </Button>
            {selectedRows.length > 0 && (
              <span>
                  <Button onClick={() => this.batchDelete(selectedRows)}>批量删除</Button>
                </span>
            )}
          </div>
          <TableList
            className={styles.tdPadding}
            selectedRows={selectedRows}
            loading={loading}
            data={data}
            columns={this.columns}
            onSelectRow={this.handleSelectRows}
            onChange={this.handleStandardTableChange.bind(this)}
            rowKey={record => record.id}
          />
        </div>
        {stepFormValues && Object.keys(stepFormValues).length ? (
          <UpdateForm
            {...updateMethods}
            updateModalVisible={updateModalVisible}
            values={stepFormValues}
            linkInfo={linkInfo}
            unicodeList={unicodeList}
            uploading={uploading}
          />
        ) : null}
        {detailsData && detailsData.id ? (
          <Details {...detailsMethods} detailVisible={detailVisible} form={form} detailsData={detailsData}/>
        ) : null}
      </Card>
    );
  }
}

class Details extends PureComponent {

  render() {
    const {detailVisible, detailHandelVisible, form, detailsData} = this.props;
    return (
      <Modal
        destroyOnClose
        width={800}
        title="查看详情"
        visible={detailVisible}
        onOk={() => detailHandelVisible()}
        onCancel={() => detailHandelVisible()}
        footer={[
          <Button key="back" type="primary" onClick={() => detailHandelVisible()}>返回</Button>
        ]}
        className={styles.viewMore}
      >
        <Row>
          <Col md={12}>
            <FormItem {...formLayout} label="系统名称">
              {detailsData.name}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem {...formLayout} label="IP地址">
              {detailsData.ipAddr}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem {...formLayout} label="端口号">
              {detailsData.port}
            </FormItem>
          </Col>
          <Col md={12}>
            <FormItem {...formLayout} label="用户名">
              {detailsData.userCode}
            </FormItem>
          </Col>
          <Col md={12}>
            <FormItem {...formLayout} label="FTP类型">
              {detailsData.ftpType == 0 ? 'FTP' : 'SFTP'}
            </FormItem>
          </Col>

          <Col md={12} style={{display: detailsData.ftpType == 1 ? 'none' : 'block',}}>
            <FormItem {...formLayout} label="模式">
              {detailsData.ftpMode == 0 ? '主动模式' : '被动模式'}
            </FormItem>
          </Col>

          <Col md={12}>
            <FormItem {...formLayout} label="语言编码">
              {detailsData.unicode}
            </FormItem>
          </Col>
          <Col md={12}>
            <FormItem {...formLayout} label="是否共享">
              {detailsData.isShare == 0 ? '不共享' : '共享'}
            </FormItem>
          </Col>
          <Col md={12} style={{display: detailsData.isShare == 1 ? 'none' : 'block',}}>
            <FormItem {...formLayout} label="自动移动">
              {detailsData.issync == 1 ? '是' : '否'}
            </FormItem>
          </Col>
          <Col md={12} style={{display: (detailsData.isShare == 1) ? 'none' : 'block',}}>
            <FormItem {...formLayout} label="帐号关系">
              {detailsData.syncType == 1 ? '无' : '主从帐号'}
            </FormItem>
          </Col>

          <Col md={24}>
            <FormItem labelCol={{span: 3}} wrapperCol={{span: 21}} label="状态">
              {detailsData.status == 0 ? '启用' : '禁用'}
            </FormItem>
          </Col>

          <Col md={24}>
            <FormItem labelCol={{span: 3}} wrapperCol={{span: 21}} label="备注">
              {detailsData.remark}
            </FormItem>
          </Col>
        </Row>
      </Modal>
    );
  }
}

export default outerFiles;
